package com.xin.net
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.Event;
	/**
	 * ...
	 * @author xin
	 */
	public class ImageLoader extends LoaderBase 
	{
		private var _bitmap:Bitmap;
		private var _loader:Loader;
		
		public function ImageLoader(url:String) 
		{
			super(url);
		}
		
		override protected function onComplete():void 
		{
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
			_loader.loadBytes(getByteArray());
		}
		
		private function loader_complete(e:Event):void
		{
			var loaderInfo:LoaderInfo = e.currentTarget as LoaderInfo;
			loaderInfo.removeEventListener(Event.COMPLETE, loader_complete);
			
			_bitmap = loaderInfo.content as Bitmap;
			
			_loader.unload();
			_loader = null;
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		public function getBitmap():Bitmap
		{
			return _bitmap;
		}
		
	}

}